package com.jxstjh.conch.common.enums;

import com.jxstjh.conch.common.dto.AppletModel;
import com.jxstjh.conch.common.dto.EmailContentModel;
import com.jxstjh.conch.common.dto.OfficialAccountsContentModel;
import com.jxstjh.conch.common.dto.SmsContentModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

/**
 * 发送渠道枚举
 */
@Getter
@ToString
@AllArgsConstructor
public enum ChannelTypeEnum {

    SMS(30, "sms(短信)", SmsContentModel.class, "sms"),
    EMAIL(40, "email(邮件)", EmailContentModel.class, "email"),
    OFFICIAL_ACCOUNT(50, "OfficialAccounts(公众号)", OfficialAccountsContentModel.class, "official_accounts"),
    APPLET(60, "Applet(小程序)", AppletModel.class, "applet"),
    ;

    private Integer code;
    private String description;
    private Class contentModelClass;
    private String codeEn;

    /**
     * 通过code获取模板class
     */
    public static Class getChanelModelClassByCode(Integer code) {
        ChannelTypeEnum[] values = values();
        for (ChannelTypeEnum value : values) {
            if (value.getCode().equals(code)) {
                return value.getContentModelClass();
            }
        }
        return null;
    }

    /**
     * 通过code获取enum
     */
    public static ChannelTypeEnum getEnumByCode(Integer code) {
        ChannelTypeEnum[] values = values();
        for (ChannelTypeEnum value : values) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }
}